using System;
using System.Reflection;
using System.Text;
using System.Web.Configuration;

namespace OpenWaves.ImageTransformations.Web
{
    public static class MachineKey
    {
        private static readonly MethodInfo hashDataMethodInfo = typeof(MachineKeySection)
            .GetMethod("HashData", BindingFlags.NonPublic | BindingFlags.Static);

        public static String HashData(string data)
        {
            var dataBytes = Encoding.ASCII.GetBytes(data);

            var hashBytes = (byte[])hashDataMethodInfo.Invoke(null, new object[] { dataBytes, null, 0, dataBytes.Length });

            return Convert.ToBase64String(hashBytes);
        }
    }
}